package com.xyht.sca_s.student_manage_system.modules.signUp.controller;


import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.org.mapper.SmsOrgStructureMapper;
import com.xyht.sca_s.student_manage_system.modules.signUp.entity.vo.SmsSignUpExportVO;
import com.xyht.sca_s.student_manage_system.modules.signUp.entity.vo.SmsSignUpSystemVO;
import com.xyht.sca_s.student_manage_system.modules.signUp.service.SmsSignUpSystemService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.Future;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-05-08
 */
@RestController
@RequestMapping("/signUp/smsSignUpSystem")
@SecretBody
public class SmsSignUpSystemController {
    @Autowired
    SmsSignUpSystemService smsSignUpSystemService;
    @Autowired
    SmsOrgStructureMapper smsOrgStructureMapper;
    @ApiOperation("学生报名申请")
    @PostMapping(value = "/smsSignUpSystemAdd")
    public ResponseResult smsSignUpSystemAdd(@RequestBody SmsSignUpSystemVO smsSignUpSystem){
        return smsSignUpSystemService.smsSignUpSystemAdd(smsSignUpSystem);
    }
    @ApiOperation("后端删除学生报名申请")
    @PostMapping("/deleteSmsSignUpSystem")
    public ResponseResult deleteSmsSignUpSystem(@RequestBody SmsSignUpSystemVO smsSignUpSystem){
        return smsSignUpSystemService.deleteSmsSignUpSystem(smsSignUpSystem);
    }
    @ApiOperation("后端查看学生报名申请")
    @GetMapping("/selectSmsSignUpSystem")
    public ResponseResult selectSmsSignUpSystem(
                                             @RequestParam(value = "student_name",required = false) String student_name,
                                             @RequestParam(value = "province_name",required = false) String province_name,
                                             @RequestParam(value = "major_name",required = false) String major_name,
                                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                             @RequestParam(value = "bg_date", required = false) String bg_date,
                                             @RequestParam(value = "end_date", required = false) String end_date){
        return smsSignUpSystemService.selectSmsSignUpSystem(student_name,province_name,major_name,pageSize,pageNum,bg_date,end_date);
    }
    @ApiOperation("后端根据id查看学生申请详情")
    @GetMapping("/selectSmsSignUpSystemById")
    public ResponseResult selectSmsSignUpSystemById(@RequestParam(value = "id",required = false) String id){
        return smsSignUpSystemService.selectSmsSignUpSystemById(id);
    }
    @ApiOperation("学生查询院系专业")
    @GetMapping("selectSmsSignUpOrgSystem")
    public ResponseResult selectSmsSignUpOrgSystem(
                                                    @RequestParam ("type") Integer type,
                                                    @RequestParam(value = "parent_id",required = false) String parent_id
                                                    ){

        return smsSignUpSystemService.selectSmsSignUpOrgSystem(type,parent_id);
    }

    @ApiOperation("批量导出")
    @PostMapping("/batch/export")
    public ResponseResult exportSmsSignUpSystem(@RequestBody SmsSignUpExportVO smsSignUpExportVO,
                                                HttpServletResponse response){
        try{
            Future<String> future = smsSignUpSystemService.exportSmsSignUpSystem(smsSignUpExportVO, response);
            while (true){
                if (future.isDone()){
                    break;
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}

